#!/bin/bash

ROOTPATH=$(cd $(dirname $0); pwd)
DISTPATH=${ROOTPATH}/dist

rm -rf ${DISTPATH}
echo "build server..."
cd server
# linux
#CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${DISTPATH}/chip-server main.go
# windows
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ${DISTPATH}/chip-server.exe main.go
# mac
#CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ${DISTPATH}/chip-server main.go
cp config.yaml ${DISTPATH}
cd ..

echo "build web..."
cd web 
npm install --registry=https://registry.npm.taobao.org
npm run build:prod ---mode=production -dest=${DISTPATH}/web/
if [ $? -eq 0 ]; then
    mv dist ../dist/web
else
    echo "build web failed!"
    exit 1
fi
cd ..
echo "build end"


